# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information

"""SliceHost Cloud Support"""

from cloudwizard.cloud import Cloud
from cloudwizard.config import Config
from cloudwizard.compute import ComputeService
from cloudwizard.compute import ComputeDevice
from cloudwizard.ssh import Connection
from pyactiveresource.activeresource import ActiveResource
import ConfigParser

class Compute( ComputeService):
    """
    """
    aws_reservation = None
    def __init__(self, username=None):
        self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='system',
                autoload=False ) 
    def create(self):
        pass


class Slice( ComputeDevice):
    """A slice is a portion of machine that you rent"""
    cloud_abbrev = 'slicehost'
    cloud_apipassword = None
    def __init__(self, config=None, machine='default',autoload=True):
        if autoload:
            self.cloud_auth = Config( cloud_abbrev=self.cloud_abbrev, type='system',
                config_name=machine ) 
            self.cloud_apipassword = self.cloud_auth.data['api_password']
            self.cloud_ipaddr = self.cloud_auth.data['ip']
            self.cloud_userid = self.cloud_auth.data['user']
            self.cloud_password = self.cloud_auth.data['password']
                
    def get_connection(self):
        """Return ssh Connection object"""
        return Connection(host=self.cloud_ipaddr, username= self.cloud_userid, 
                password=self.cloud_password)
